package com.mentalhealthplatform.global.rbac.dto.normal;

import com.mentalhealthplatform.global.rbac.model.User;
import lombok.Getter;
import lombok.Setter;

import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

@Setter
@Getter
public class BaseUserDTO {

    // Getters 和 Setters

    private UUID id;
    private String username;
    private boolean status;
    private Set<RoleDTO> roles;
    private String nickname;
    private String department;
    private String phone;
    private String password;


    public BaseUserDTO() { }

    public BaseUserDTO(UUID id, String username, boolean status) {
        this.id = id;
        this.username = username;
        this.status = status;
    }

    // 构造方法
    public BaseUserDTO(UUID id, String username, boolean status, Set<RoleDTO> roles) {
        this.id = id;
        this.username = username;
        this.status = status;
        this.roles = roles;
    }

    // 静态方法将 User 转换为 UserDTO
    public static BaseUserDTO fromUser(User user) {
        BaseUserDTO baseUserDTO = new BaseUserDTO();
        baseUserDTO.setId(user.getId());
        baseUserDTO.setUsername(user.getUsername());
        baseUserDTO.setStatus(user.isStatus());

        // 将所有 Role 转换为 RoleDTO
        baseUserDTO.setRoles(user.getRoles().stream()
                .map(RoleDTO::convertToDTO)
                .collect(Collectors.toSet()));

        return baseUserDTO;
    }


}


